//
//  MyFamilyViewController.m
//  WheatPlan
//
//  Created by giantumbrella on 15/5/21.
//  Copyright (c) 2015年 IOSTeam. All rights reserved.
//

#import "MyFamilyViewController.h"
#import "BabyViewController.h"
#import "SettingViewController.h"
#import "MessageViewController.h"
#import "AddBabyViewController.h"
#import "DoorTeachViewController.h"
#import "EvaluateViewController.h"
#import "SameCityViewController.h"
#import "HomePaternityViewController.h"
#import "BabyManager.h"
#import "LoginViewController.h"

@interface MyFamilyViewController ()
{
    UIButton *addbabyBtn;
    UIButton *backBtn;
}
@property(nonatomic,copy)NSMutableArray *babyNameArray;
@property(nonatomic,copy)NSMutableArray *babyTimeArray;
@property(nonatomic,copy)NSMutableArray *babydayArray;
@property(nonatomic,copy)NSString *babydayStr;

@property(nonatomic,copy)NSMutableArray *babyIDArray;
@property(nonatomic,copy)NSMutableArray *babyWt;
@property(nonatomic,copy)NSMutableArray *babyHt;
@property(nonatomic,copy)NSMutableArray *nownameArray;
@property(nonatomic,copy)NSMutableArray *nowtimeArray;
@property(nonatomic,copy)NSMutableArray *nowIDArray;

@end

@implementation MyFamilyViewController

//- (NSMutableArray *)nameArray
//{
//    if (nil == _babyNameArray)
//    {
//        _babyNameArray = [NSMutableArray array];
//    }
//    return _babyNameArray;
//}
//
//- (NSMutableArray *)timeArray
//{
//    if (nil == _babyTimeArray)
//    {
//        _babyTimeArray = [NSMutableArray array];
//    }
//    return _babyTimeArray;
//}
-(void)viewWillAppear:(BOOL)animated{
    
    

    ////NSLog(@"%@ogegegegegegegege",[BabyManager shareInstance].babyId);

    
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString *ID = [user objectForKey:@"ID"];
    [MBProgressHUD showHUDAddedTo:_tableView animated:YES];

    NSDictionary *param = @{@"userId": ID};
    [UserDAL getHomeDataWithParams: param withBlock:^(NSDictionary *data, NSError *error) {

        if (data) {
                        //NSLog(@"=========================%@",data);
            NSArray *dataList = data[@"dataList"];
           amountOutDoor = data[@"amountOutDoor"];
           amountPreSchool = data[@"amountPreSchool"];
           amountSameCity = data[@"amountSameCity"];
            
            for (NSDictionary *myDic in dataList) {
                NSString * name = [myDic objectForKey:@"babyName"];
                [_babyNameArray addObject:name];
                [_babyTimeArray addObject:myDic[@"babyAge"]];
                [_babyIDArray addObject:myDic[@"ID"]];
                [_babyWt addObject:myDic[@"babyWeight"]];
                [_babyHt addObject:myDic[@"babyHeight"]];
                NSString * day = [myDic objectForKey:@"babyDay"];
                NSString * Year = [NSString stringWithFormat:@"%d",[day intValue]/365];
                NSString * day2 = [NSString stringWithFormat:@"%d",[day intValue]-[Year intValue]*365];
                NSString * April = [NSString stringWithFormat:@"%d",[day2 intValue]/30];
//                //NSLog(@"%@岁%@月%@",day1,day3,day2);
                
                if ([April isEqualToString:@"0"]) {
                    if ([Year isEqualToString:@"0"]&&[April isEqualToString:@"0"]){
                        
                        _babydayStr = [NSString stringWithFormat:@"1个月"];
                        
                        
                    }else{
                        _babydayStr = [NSString stringWithFormat:@"%@岁",Year];
                        
                    }
                    
                    
                }else if ([Year isEqualToString:@"0"]){
                    
                    if ([Year isEqualToString:@"0"]&&[April isEqualToString:@"0"]){
                        
                        _babydayStr = [NSString stringWithFormat:@"1个月"];
                        
                        
                    }else{
                        _babydayStr = [NSString stringWithFormat:@"%@个月",April];
                        
                        
                    }
                    
                    
                }else{
                    
                    _babydayStr = [NSString stringWithFormat:@"%@岁%@个月",Year,April];
                    
                    
                }
                
                [_babydayArray addObject:_babydayStr];
                //NSLog(@"%@",_babydayStr);

                [_babyTimeArray addObject:myDic[@"babyAge"]];

                
                
                
                //                ////NSLog(@"%@,%@,%@",_babyNameArray,_babyIDArray,_babyWt);
                //                ////NSLog(@"%@呵呵呵%@",_babyIDArray,_babyNameArray);
                


                
            }
            if (dataList.count == 0) {
                
                UIButton * btnClick = [UIButton buttonWithType:UIButtonTypeCustom];
                btnClick.frame = CGRectMake(0, NavbarHight, SCREEN_WIDTH, (76*3+22)/2);
                [btnClick addTarget:self action:@selector(goAddBaby) forControlEvents:UIControlEventTouchUpInside];
                btnClick.userInteractionEnabled = YES;
                [self.view addSubview:btnClick];

            }

            [_tableView reloadData];
            
        }
        else
        {
            
            
            
            
        }
        
        //        [_tableView reloadData];
        
        
    }];
    
    NSUserDefaults *user1 = [NSUserDefaults standardUserDefaults];
    NSString *babyNameD = [user1 objectForKey:@"babyName"];
    
    NSUserDefaults *user2 = [NSUserDefaults standardUserDefaults];
    NSString *babyAgeD = [user2 objectForKey:@"babyAge"];
    
    //    ////NSLog(@"%@家家爱爱就爱爱就爱案件%@",babyNameD,babyAgeD);
    
    
    nameStr = babyNameD;
    ageStr = babyAgeD;
    //NSLog(@"%@.%@",nameStr,ageStr);


    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    
    NSArray *allVCS = self.tabBarController.childViewControllers;
    
//    //NSLog(@"allVCS:%@",allVCS);
    
    _babyTimeArray = [NSMutableArray array];
    _babyNameArray = [NSMutableArray array];
    _babyIDArray = [NSMutableArray array];
    _babyWt = [NSMutableArray array];
    _babyHt = [NSMutableArray array];
    _babydayArray = [NSMutableArray array];


    NSString *babyID = @"1";
    NSUserDefaults *userBa = [NSUserDefaults standardUserDefaults];
    [userBa setObject:babyID forKey:@"babyID"];
//    ////NSLog(@"%@ogegegegegegegege",babyID);
    
    //设置导航栏头文字
    self.navigationItem.title = @"我家";
    //设置导航栏背景颜色
    [self.navigationController.navigationBar setBarTintColor:[GetFileModel colorWithHexString:@"#34bd81" alpha:1]];
    //设置导航栏字体颜色
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName,nil]];
    UIBarButtonItem *rightBtn = [[UIBarButtonItem alloc]
                                 initWithTitle:@"宝宝"
                                 style:UIBarButtonItemStylePlain
                                 target:self
                                 action:@selector(turntoBaby)];
    [rightBtn setTintColor:[UIColor whiteColor]];
    self.navigationItem.rightBarButtonItem = rightBtn;
    
    _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    //隐藏分割线
     _tableView.separatorStyle = UITableViewCellEditingStyleNone;
    

    [self.view addSubview:_tableView];
    _tableView.backgroundColor = UIColorWithRGBA(232, 232, 232, 1);
    // Do any additional setup after loading the view from its nib.
    
    
    
//    NSDictionary *param = @{@"userId": @"1"};
//    [UserDAL getBabysParams:param withBlock:^(NSDictionary *data, NSError *error) {
//        if (data) {
//            //NSLog(@"=========================%@",data);
//
//            NSArray *myArray =data[@"dataList"];
//            for (NSDictionary *myDic in myArray) {
//                [_nameArray addObject:myDic[@"babyName"]];
//                [_timeArray addObject:myDic[@"babyAge"]];
//                [_babyIdArray addObject:myDic[@"ID"]];
//            }
//            [_myTable reloadData];
//            //            [self ShowProgressHUDwithMessage:data[@"msg"]];
//            
//        }
//        else
//        {
//            
//        }
//    }];
//
    
    
}

-(void)turntoBaby{
    
    BabyViewController *babyVC = [[BabyViewController alloc]init];
//    ////NSLog(@"怎么没名字呢？？%@",_babyNameArray);
//    babyVC.nameArray = _babyNameArray;
//    babyVC.timeArray = _babyTimeArray;
//    babyVC.babyIdArray  =_babyIDArray;
    UINavigationController * nav = [[UINavigationController alloc]initWithRootViewController:babyVC];
    [self  presentViewController:nav animated:YES completion:nil];
    
}
-(void)viewDidAppear:(BOOL)animated{
    
    
    self.tabBarController.tabBar.selectedImageTintColor = [GetFileModel colorWithHexString:@"#34bd81" alpha:1];
//    ////NSLog(@"%@啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊",[BabyManager shareInstance].babyId);

//    [_tableView reloadData];
    
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark--- tableViewDelegate 每个区的行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section==0) {
        return 4;
        
    }else{
        
        return 2;
    
    }
}

#pragma mark--- tableViewDelegate 区尾的高度

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    if (section == 0) {
        return 11;
    } else {
        return 0;
        
    }
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section == 0) {
        
        if (indexPath.row == 0) {
            
            return   (76*3+22)/2;
        }else{
            
            return   93/2;
            
        }
        
    }else{
       return   93/2;
    }
    
    
}

#pragma mark--- tableViewDelegate cell

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [MBProgressHUD hideHUDForView:_tableView animated:YES];

//    static NSString *NOTIFY = @"cell";
//    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:NOTIFY];
    NSString *CellIdentifier = [NSString stringWithFormat:@"Cell%ld%ld", (long)[indexPath section], (long)[indexPath row]];//以indexPath来唯一确定cell
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; //出列可重用的cell

    
    if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        
        
        
    }
    


    NSUserDefaults *user1 = [NSUserDefaults standardUserDefaults];
    NSString *nasty = [user1 objectForKey:@"nasty"];
    
    if ([nasty isEqualToString:@"1"]) {
//        //NSLog(@"shanwanle");
        
        //NSLog(@"%lujiushizhemeduo",(unsigned long)_babyNameArray.count);
        
        
            if (indexPath.section ==0) {
                
                
                if (indexPath.row == 0) {
                    
                    
                    
                  
                    UIImageView * image = [[UIImageView alloc]init];
                    image.frame = CGRectMake(0, 0, SCREEN_WIDTH, (76*3+22)/2);
                    image.image = [UIImage imageNamed:@"_0001_圆角矩形-2"];
                    [cell addSubview:image];
                    
                    
                    
                    UILabel * lab = [[UILabel alloc]init];
                    lab.frame = CGRectMake(30, 98/2, SCREEN_WIDTH-60, 18);
                    lab.text =@"暂无宝宝,点击添加宝宝";
                    lab.font = [UIFont systemFontOfSize:18];
                    lab.textAlignment = NSTextAlignmentCenter;
                    [image addSubview:lab];
                    

                    
                    
                }else{
                    
                    _tableView.rowHeight = 93/2;
                    
                    
                    
                    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
                    
                    NSMutableArray * muArry = [NSMutableArray arrayWithObjects:@"        上门早教",@"        同城解读",@"        同城亲子", nil];
                    cell.textLabel.text = [muArry objectAtIndex:indexPath.row-1];
                    cell.textLabel.font = [UIFont systemFontOfSize:16];
                    
                    _image = [[UIImageView alloc]init];
                    _image.frame = CGRectMake(13, (93/2-22)/2, 22, 22);
                    _image.image = [UIImage imageNamed:[NSString stringWithFormat:@"%ld.png",indexPath.row]];
                    [cell addSubview:_image];
                    
                    
                    
                }
                
                
                
            }else if (indexPath.section == 1){
                
                
                
                
                
                
                
                if (indexPath.row!=2) {
                    
                    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
                    NSMutableArray * muArry = [NSMutableArray arrayWithObjects:@"        消息中心",@"        设置", nil];
                    cell.textLabel.text = [muArry objectAtIndex:indexPath.row];
                    cell.textLabel.font = [UIFont systemFontOfSize:16];
                    
                    _image = [[UIImageView alloc]init];
                    _image.frame = CGRectMake(13, (93/2-22)/2, 22, 22);
                    _image.image = [UIImage imageNamed:[NSString stringWithFormat:@"%d.png",indexPath.row+4]];
                    [cell addSubview:_image];
                    
                    
                    
                }
                
            }
            
//
        
            
            
            
//        }
    
    
        
    }else if ([nasty isEqualToString:@"3"])
    {
        
        
        
        if (_babyNameArray.count != 0) {
            
            
            if ([BabyManager shareInstance].babyId == nil) {
                [BabyManager shareInstance].babyId = _babyIDArray[_babyIDArray.count-1];
                [BabyManager shareInstance].homeName = _babyNameArray[_babyNameArray.count-1];
                
                
                
            }else{
                
                
                
            }
            
            
            
            if (indexPath.section ==0) {
                
                
                if (indexPath.row == 0) {
                    
                    
                    
                    
                    UIImageView * image = [[UIImageView alloc]init];
                    image.frame = CGRectMake(0, 0, SCREEN_WIDTH, (76*3+22)/2);
                    image.image = [UIImage imageNamed:@"_0001_圆角矩形-2"];
                    [cell addSubview:image];
                    
                    
                    
                    
                    if ([nameStr isEqualToString:@""]) {
                        
                        
                        nameStr = [NSString stringWithFormat:@"%@",_babyNameArray[_babyNameArray.count-1]];
                        //                        //NSLog(@"111");
                        [BabyManager shareInstance].babyId = _babyIDArray[_babyNameArray.count-1];
                        
                    }
                    
                    
                    if ([ageStr isEqualToString:@""]) {
                        
                        ageStr = [NSString stringWithFormat:@"%@",_babydayArray[_babydayArray.count-1]];
                        //                        //NSLog(@"222");
                        
                        
                    }
                    //                    //NSLog(@"%@",[BabyManager shareInstance].babyId);
                    
                    UILabel * lab = [[UILabel alloc]init];
                    lab.frame = CGRectMake(30, 98/2, SCREEN_WIDTH-60, 18);
                    if(nameStr && ageStr){
                        if ([ageStr isEqualToString:@"0岁"]) {
                            lab.text =[NSString stringWithFormat:@"您的宝宝%@已经一个月",nameStr];
                            
                        }else{
                            
                            lab.text =[NSString stringWithFormat:@"您的宝宝%@已经%@",nameStr,ageStr];
                            
                        }

//                        lab.text =[NSString stringWithFormat:@"您的宝宝%@已经%@",nameStr,ageStr];
                    }else{
                        
                       lab.text =[NSString stringWithFormat:@"您的宝宝%@已经%@",_babyNameArray[_babyNameArray.count-1],_babydayArray[_babydayArray.count-1]];
                        [BabyManager shareInstance].babyId = _babyIDArray[_babyNameArray.count-1];

                        
                    }

                    lab.text =[NSString stringWithFormat:@"您的宝宝%@已经%@",nameStr,ageStr];
                    lab.adjustsFontSizeToFitWidth = YES;
                    lab.font = [UIFont systemFontOfSize:18];
                    lab.textAlignment = NSTextAlignmentCenter;
                    [image addSubview:lab];
                    
                    UILabel * lab1 = [[UILabel alloc]init];
                    lab1.frame = CGRectMake(10, lab.frame.origin.y+lab.frame.size.height+25, 149, 20);
                    lab1.text = [NSString stringWithFormat:@"身高:%@",_babyHt[0]];
                    lab1.font = [UIFont systemFontOfSize:15];
                    lab1.textAlignment = NSTextAlignmentLeft;
                    lab1.adjustsFontSizeToFitWidth = YES;
                    [image addSubview:lab1];
                    
                    UILabel * lab2 = [[UILabel alloc]init];
                    lab2.frame = CGRectMake(lab1.frame.origin.x+lab1.frame.size.width+5, lab.frame.origin.y+lab.frame.size.height+25, 149-5, 20);
                    lab2.text = [NSString stringWithFormat:@"体重:%@",_babyWt[0]];
                    lab2.font = [UIFont systemFontOfSize:15];
                    lab2.textAlignment = NSTextAlignmentLeft;
                    lab2.adjustsFontSizeToFitWidth = YES;
                    [image addSubview:lab2];
                    
                    
                    
                    
                }else{
                    
                    
                    
                    
                    
                    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
                    
                    NSMutableArray * muArry = [NSMutableArray arrayWithObjects:@"        上门早教",@"        同城解读",@"        同城亲子", nil];
                    cell.textLabel.text = [muArry objectAtIndex:indexPath.row-1];
                    cell.textLabel.font = [UIFont systemFontOfSize:16];
                    
                    _image = [[UIImageView alloc]init];
                    _image.frame = CGRectMake(13, (93/2-22)/2, 22, 22);
                    _image.image = [UIImage imageNamed:[NSString stringWithFormat:@"%ld.png",indexPath.row]];
                    [cell addSubview:_image];
                    
                    _image1 = [[UIImageView alloc]init];
                    _image1.frame = CGRectMake(SCREEN_WIDTH-79/2-20, (93/2-20)/2, 20, 20);
                    _image1.image = [UIImage imageNamed:@"6.png"];
                    [cell addSubview:_image1];
                    
                    
                    
                    
                    NSMutableArray * city = [NSMutableArray arrayWithObjects:amountPreSchool,amountSameCity,amountOutDoor, nil];
                    
                    UILabel * lab = [[UILabel alloc]init];
                    lab.frame = CGRectMake(0, 0, 21, 20);
                    if ([city[indexPath.row-1] integerValue] == 0) {
                        
                        
                        [_image1 removeFromSuperview];
                        
                    }else{
                        
                        lab.text = [NSString stringWithFormat:@"%@",city[indexPath.row-1]];
                        
                        
                    }
                    lab.textColor = [UIColor whiteColor];
//                    lab.backgroundColor = [UIColor blackColor];
                    lab.font = [UIFont systemFontOfSize:9];
                    lab.textAlignment = NSTextAlignmentCenter;
                    [_image1 addSubview:lab];
                    
                    
                    
                }
                
                
                
            }else if (indexPath.section == 1){
                
                
                
                
                
                
                
                if (indexPath.row!=2) {
                    
                    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
                    NSMutableArray * muArry = [NSMutableArray arrayWithObjects:@"        消息中心",@"        设置", nil];
                    cell.textLabel.text = [muArry objectAtIndex:indexPath.row];
                    cell.textLabel.font = [UIFont systemFontOfSize:16];
                    
                    _image = [[UIImageView alloc]init];
                    _image.frame = CGRectMake(13, (93/2-22)/2, 22, 22);
                    _image.image = [UIImage imageNamed:[NSString stringWithFormat:@"%d.png",indexPath.row+4]];
                    [cell addSubview:_image];
                    
                    
                    
                }
                
                
            }
            
            
            
            
            
            //        //NSLog(@"22222");
        }else{
            
            
            if (indexPath.section ==0) {
                
                
                if (indexPath.row == 0) {
                    
                    
                    
                    
                    UIImageView * image = [[UIImageView alloc]init];
                    image.frame = CGRectMake(0, 0, SCREEN_WIDTH, (76*3+22)/2);
                    image.image = [UIImage imageNamed:@"_0001_圆角矩形-2"];
                    [cell addSubview:image];
                    
                    
                    
                    
                    
                    UILabel * lab = [[UILabel alloc]init];
                    lab.frame = CGRectMake(30, 98/2, SCREEN_WIDTH-60, 18);
                    lab.text =@"暂无宝宝,点击添加宝宝";
                    lab.font = [UIFont systemFontOfSize:18];
                    lab.textAlignment = NSTextAlignmentCenter;
                    [image addSubview:lab];
                    
                    
                    
                    
                }else{
                    
                    
                    
                    
                    
                    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
                    
                    NSMutableArray * muArry = [NSMutableArray arrayWithObjects:@"        上门早教",@"        同城解读",@"        同城亲子", nil];
                    cell.textLabel.text = [muArry objectAtIndex:indexPath.row-1];
                    cell.textLabel.font = [UIFont systemFontOfSize:16];
                    
                    _image = [[UIImageView alloc]init];
                    _image.frame = CGRectMake(13, (93/2-22)/2, 22, 22);
                    _image.image = [UIImage imageNamed:[NSString stringWithFormat:@"%ld.png",indexPath.row]];
                    [cell addSubview:_image];
                    
                    
                    
                }
                
                
                
            }else if (indexPath.section == 1){
                
                
                
                
                
                
                
                if (indexPath.row!=2) {
                    
                    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
                    NSMutableArray * muArry = [NSMutableArray arrayWithObjects:@"        消息中心",@"        设置", nil];
                    cell.textLabel.text = [muArry objectAtIndex:indexPath.row];
                    cell.textLabel.font = [UIFont systemFontOfSize:16];
                    
                    _image = [[UIImageView alloc]init];
                    _image.frame = CGRectMake(13, (93/2-22)/2, 22, 22);
                    _image.image = [UIImage imageNamed:[NSString stringWithFormat:@"%d.png",indexPath.row+4]];
                    [cell addSubview:_image];
                    
                    
                    
                }
                //
                
            }
            
            
            
            
            
            
        }
        
        
        
        
        
        
    } else{
        
        
        
        if (_babyNameArray.count != 0) {
            
            
            if ([BabyManager shareInstance].babyId == nil) {
                [BabyManager shareInstance].babyId = _babyIDArray[_babyIDArray.count-1];
                [BabyManager shareInstance].homeName = _babyNameArray[_babyNameArray.count-1];
                
                
                
            }else{
                
                
                
            }
            
            
            
            if (indexPath.section ==0) {
                
                
                if (indexPath.row == 0) {
                    
                    
                    
                    
                    UIImageView * image = [[UIImageView alloc]init];
                    image.frame = CGRectMake(0, 0, SCREEN_WIDTH, (76*3+22)/2);
                    image.image = [UIImage imageNamed:@"_0001_圆角矩形-2"];
                    [cell addSubview:image];
                    
                    
                    
                    
                    if ([nameStr isEqualToString:@""]) {
                        
                        
                        nameStr = [NSString stringWithFormat:@"%@",_babyNameArray[_babyNameArray.count-1]];
//                        //NSLog(@"111");
                        [BabyManager shareInstance].babyId = _babyIDArray[_babyNameArray.count-1];
                        
                    }
                    
                    
                    if ([ageStr isEqualToString:@""]) {
                        
                        ageStr = [NSString stringWithFormat:@"%@",_babydayArray[_babydayArray.count-1]];
//                        //NSLog(@"222");
                        
                        
                    }
//                    //NSLog(@"%@",[BabyManager shareInstance].babyId);
                    
                    UILabel * lab = [[UILabel alloc]init];
                    lab.frame = CGRectMake(30, 98/2, SCREEN_WIDTH-60, 18);
                    if(nameStr && ageStr){
                        if ([ageStr isEqualToString:@"0岁"]) {
                            lab.text =[NSString stringWithFormat:@"您的宝宝%@已经一个月",nameStr];

                        }else{
                            
                            lab.text =[NSString stringWithFormat:@"您的宝宝%@已经%@",nameStr,ageStr];

                        }
                    }else{
                        
                        lab.text =[NSString stringWithFormat:@"您的宝宝%@已经%@",_babyNameArray[_babyNameArray.count-1],_babydayArray[_babydayArray.count-1]];
                        [BabyManager shareInstance].babyId = _babyIDArray[_babyNameArray.count-1];

                        
                    }
              
                    lab.font = [UIFont systemFontOfSize:18];
                    lab.adjustsFontSizeToFitWidth = YES;
                    lab.textAlignment = NSTextAlignmentCenter;
                    [image addSubview:lab];
                    
                    UILabel * lab1 = [[UILabel alloc]init];
                    lab1.frame = CGRectMake(10, lab.frame.origin.y+lab.frame.size.height+25, 149, 20);
                    lab1.text = [NSString stringWithFormat:@"身高:%@",_babyHt[0]];
                    lab1.font = [UIFont systemFontOfSize:15];
                    lab1.adjustsFontSizeToFitWidth = YES;
                    lab1.textAlignment = NSTextAlignmentLeft;
                    [image addSubview:lab1];
                    
                    UILabel * lab2 = [[UILabel alloc]init];
                    lab2.frame = CGRectMake(lab1.frame.origin.x+lab1.frame.size.width+5, lab.frame.origin.y+lab.frame.size.height+25, 149 - 5, 20);
                    lab2.text = [NSString stringWithFormat:@"体重:%@",_babyWt[0]];
                    lab2.font = [UIFont systemFontOfSize:15];
                    lab2.adjustsFontSizeToFitWidth = YES;
                    lab2.textAlignment = NSTextAlignmentLeft;
                    [image addSubview:lab2];
                    
                    
                    
                    
                }else{
                    
                
                    
                    
                    
                    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
                    
                    NSMutableArray * muArry = [NSMutableArray arrayWithObjects:@"        上门早教",@"        同城解读",@"        同城亲子", nil];
                    cell.textLabel.text = [muArry objectAtIndex:indexPath.row-1];
                    cell.textLabel.font = [UIFont systemFontOfSize:16];
                    
                    _image = [[UIImageView alloc]init];
                    _image.frame = CGRectMake(13, (93/2-22)/2, 22, 22);
                    _image.image = [UIImage imageNamed:[NSString stringWithFormat:@"%ld.png",indexPath.row]];
                    [cell addSubview:_image];
                    
                    _image1 = [[UIImageView alloc]init];
                    _image1.frame = CGRectMake(SCREEN_WIDTH-79/2-20, (93/2-20)/2, 20, 20);
                    _image1.image = [UIImage imageNamed:@"6.png"];
                    [cell addSubview:_image1];
                    
                    
                    
                    
                    NSMutableArray * city = [NSMutableArray arrayWithObjects:amountPreSchool,amountSameCity,amountOutDoor, nil];
                    
                    UILabel * lab = [[UILabel alloc]init];
                    lab.frame = CGRectMake(0, 0, 21, 20);
                    if ([city[indexPath.row-1] integerValue] == 0) {
                        
                        
                        [_image1 removeFromSuperview];
                        
                    }else{
                        
                        lab.text = [NSString stringWithFormat:@"%@",city[indexPath.row-1]];
                        
                        
                    }
                    lab.textColor = [UIColor whiteColor];
//                    lab.backgroundColor = [UIColor blackColor];
                    lab.font = [UIFont systemFontOfSize:9];
                    lab.textAlignment = NSTextAlignmentCenter;
                    [_image1 addSubview:lab];
                    
                    
                    
                }
                
                
                
            }else if (indexPath.section == 1){
                
                
                
                
               
                
                
                if (indexPath.row!=2) {
                    
                    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
                    NSMutableArray * muArry = [NSMutableArray arrayWithObjects:@"        消息中心",@"        设置", nil];
                    cell.textLabel.text = [muArry objectAtIndex:indexPath.row];
                    cell.textLabel.font = [UIFont systemFontOfSize:16];
                    
                    _image = [[UIImageView alloc]init];
                    _image.frame = CGRectMake(13, (93/2-22)/2, 22, 22);
                    _image.image = [UIImage imageNamed:[NSString stringWithFormat:@"%d.png",indexPath.row+4]];
                    [cell addSubview:_image];
                    
                    
                    
                }
                
                
            }
            
            
            
            
            
            //        //NSLog(@"22222");
        }else{
            
            
            if (indexPath.section ==0) {
                
                
                if (indexPath.row == 0) {
                    
                    
                    
                    
                    UIImageView * image = [[UIImageView alloc]init];
                    image.frame = CGRectMake(0, 0, SCREEN_WIDTH, (76*3+22)/2);
                    image.image = [UIImage imageNamed:@"_0001_圆角矩形-2"];
                    [cell addSubview:image];
                    
                    
                    
                    
                    
                    UILabel * lab = [[UILabel alloc]init];
                    lab.frame = CGRectMake(30, 98/2, SCREEN_WIDTH-60, 18);
                    lab.text =@"暂无宝宝,点击添加宝宝";
                    lab.font = [UIFont systemFontOfSize:18];
                    lab.textAlignment = NSTextAlignmentCenter;
                    [image addSubview:lab];
                    
                    
                    
                    
                }else{
                    
                   
                    
                    
                    
                    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
                    
                    NSMutableArray * muArry = [NSMutableArray arrayWithObjects:@"        上门早教",@"        同城解读",@"        同城亲子", nil];
                    cell.textLabel.text = [muArry objectAtIndex:indexPath.row-1];
                    cell.textLabel.font = [UIFont systemFontOfSize:16];
                    
                    _image = [[UIImageView alloc]init];
                    _image.frame = CGRectMake(13, (93/2-22)/2, 22, 22);
                    _image.image = [UIImage imageNamed:[NSString stringWithFormat:@"%ld.png",indexPath.row]];
                    [cell addSubview:_image];
                    
                    
                    
                }
                
                
                
            }else if (indexPath.section == 1){
                
                
                
                
             
                
                
                if (indexPath.row!=2) {
                    
                    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
                    NSMutableArray * muArry = [NSMutableArray arrayWithObjects:@"        消息中心",@"        设置", nil];
                    cell.textLabel.text = [muArry objectAtIndex:indexPath.row];
                    cell.textLabel.font = [UIFont systemFontOfSize:16];
                    
                    _image = [[UIImageView alloc]init];
                    _image.frame = CGRectMake(13, (93/2-22)/2, 22, 22);
                    _image.image = [UIImage imageNamed:[NSString stringWithFormat:@"%d.png",indexPath.row+4]];
                    [cell addSubview:_image];
                    
                    
                    
                }
                //
                
            }
            
            
            
            
            
            
        }
        
        
        
        

        
    }
    
    
    return cell;
    
    
}
#pragma mark--- tableViewDelegate 有几个区
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    
    
    if (indexPath.section == 0) {
        
        if (indexPath.row == 1) {
            
            DoorTeachViewController *setVC = [[DoorTeachViewController alloc]init];
            
            UINavigationController * nav = [[UINavigationController alloc]initWithRootViewController:setVC];
            [self  presentViewController:nav animated:YES completion:nil];

        }
        
        
        if (indexPath.row == 2) {
            
            SameCityViewController *setVC = [[SameCityViewController alloc]init];
            
            UINavigationController * nav = [[UINavigationController alloc]initWithRootViewController:setVC];
            [self  presentViewController:nav animated:YES completion:nil];

        }
        
        if (indexPath.row == 3) {
            
            HomePaternityViewController *setVC = [[HomePaternityViewController alloc]init];
            
            UINavigationController * nav = [[UINavigationController alloc]initWithRootViewController:setVC];
            [self  presentViewController:nav animated:YES completion:nil];

        }
        
        
        
    }else if (indexPath.section == 1){
        
        if (indexPath.row == 0) {
            
            MessageViewController *messageVC = [[MessageViewController alloc]init];
            UINavigationController * nav = [[UINavigationController alloc]initWithRootViewController:messageVC];
            [self  presentViewController:nav animated:YES completion:nil];
            
//            NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
//            NSString *currentVersion = [infoDic objectForKey:@"CFBundleVersion"];
//            ////NSLog(@"%@得得",currentVersion);

        }
        
        
        if (indexPath.row == 1) {
            
            SettingViewController *setVC = [[SettingViewController alloc]init];
            
            UINavigationController * nav = [[UINavigationController alloc]initWithRootViewController:setVC];
            [self  presentViewController:nav animated:YES completion:nil];

            
        }
        
        
//        if (indexPath.row == 2) {
//            
//            
//            
//            LoginViewController * myTableView = [[LoginViewController alloc]init];
//            UINavigationController * nav = [[UINavigationController alloc]initWithRootViewController:myTableView];
//            [self  presentViewController:nav animated:YES completion:nil];
//
//            
//            
//        }
//        
//        
        
    }
    
    
    
    
//    if (indexPath.section==1) {
//        if (indexPath.row==0) {
//            
//        }
//        if (indexPath.row==1) {
//            
//        }
//        if (indexPath.row==2) {
//            
//        }
//    }
//    if (indexPath.section==2) {
//        if (indexPath.row == 0) {
//            
//        } else if(indexPath.row ==1)
//        {
//            
//        }
//        
//    }
    
}
-(void)goAddBaby{
    
    
    //NSLog(@"wodianle");
    
    AddBabyViewController *addBabyVC = [[AddBabyViewController alloc]init];
    addBabyVC.myBabyId = @"0";
    addBabyVC.gender = @"3";
    addBabyVC.city = @"1";
    UINavigationController * nav = [[UINavigationController alloc]initWithRootViewController:addBabyVC];
    [self  presentViewController:nav animated:YES completion:nil];

    
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
